package com.atguigu.user.config;
//存放配置类，一些配置如登录拦截器，安全配置等

import com.atguigu.user.Interceptor.LoginInterceptor;
import com.atguigu.user.Interceptor.RefreshTokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;




/**
 * 首先使用的拦截器是RefreshTokenInterceptor  它的目的是：如果用户已经登录，那么刷新其token，避免token过期
 * 其次使用的拦截器是LoginInterceptor  它的目的是避免未登录的用户访问未授权的接口
 */

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截器，拦截需要登录才能做的请求，判断是否已经登录
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/songList/**",
                "/singer/**",
                "/song/**",
                "/user/register",
                "/user/**"
        ).order(1);
        registry.addInterceptor(new RefreshTokenInterceptor(redisTemplate)).addPathPatterns("/**").order(0);
    }
}
